package com.dadaguai.mapper;

import com.dadaguai.domain.ForumArticle;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 王半仙
 * @description 针对表【forum_article(文章信息)】的数据库操作Mapper
 * @createDate 2023-10-20 11:28:40
 * @Entity com.dadaguai.domain.ForumArticle
 */
public interface ForumArticleMapper extends BaseMapper<ForumArticle> {

    /**
     * 获取帖子分页数据
     *
     * @param boardId     板块id
     * @param sort        排序方式
     * @param index       查询数据起始下标
     * @param size        每页数据条数
     * @param str 搜索关键字
     * @return
     */
    List<ForumArticle> getArticle(
            @Param("boardId") String boardId,
            @Param("sort") String sort,
            @Param("index") Integer index,
            @Param("size") Integer size,
            @Param("str") String str);

    /**
     * 根据帖子id查询用户id
     * @param articleId
     * @return
     */
    @Select("select user_id from forum_article where article_id = #{articleId}")
    String selectAuthorId(@Param("articleId") String articleId);

    /**
     * 更新帖子阅读量
     * @param articleId
     */
    @Update("update forum_article set read_count = read_count + 1 where article_id = #{articleId}")
    void updateReadCount(@Param("articleId") String articleId);

    @Update("update forum_article set good_count = good_count+1 where article_id=#{articleId}")
    void addGoodCount(@Param("articleId") String articleId);

    @Update("update forum_article set good_count = good_count-1 where article_id=#{articleId}")
    void minusGoodCount(@Param("articleId") String articleId);


    Integer selectCountByBoardId(@Param("boardId") String boardId, @Param("searchField") String searchField);
}




